package com.tarena.lbs.basic.web.controller;

import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.basic.web.service.IBusinessService;
import com.tarena.lbs.common.basic.converter.BusinessConverter;
import com.tarena.lbs.pojo.basic.bo.BusinessBO;
import com.tarena.lbs.pojo.basic.param.BusinessParam;
import com.tarena.lbs.pojo.basic.query.BusinessQuery;
import com.tarena.lbs.pojo.basic.vo.BusiStoreVO;
import com.tarena.lbs.pojo.basic.vo.BusinessVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.annotation.Resource;
import javax.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "商家模块")
//@RequestMapping("/admin/basic/business/info")
@Slf4j
public class BusinessController {

    @Resource
    private IBusinessService businessService;

    @Resource
    private BusinessConverter businessConverter;


    @PostMapping("/admin/basic/business/info/save")
    @ApiOperation("后端管理:新增商家信息")
    @ApiImplicitParams(
            value = {
                    @ApiImplicitParam(name = "businessParam", value = "BusinessParam",
                            required = false, dataType = "BusinessParam")
            })
    public Result<Void> save(@RequestBody @Valid BusinessParam businessParam) {
        log.info("新增商家的基本信息:{}", businessParam);
        businessService.saveParam(businessParam);
        return Result.success();
    }


    @GetMapping("/admin/basic/business/info/detail/{id}")
    @ApiOperation("后端管理:商家基本信息详情")
    public Result<BusiStoreVO> detail(@PathVariable("id") Integer id) {
        BusiStoreVO businessVO = businessService.detail(id);
        return new Result<>(businessVO);
    }

    @GetMapping("/basic/business/info/detail/{id}")
    public Result<BusiStoreVO> detailApp(@PathVariable("id") Integer id) {
        BusiStoreVO businessVO = businessService.detail(id);
        return new Result<>(businessVO);
    }


    @GetMapping("/admin/basic/business/info/list")
    public Result<PageResult<BusinessVO>> list(BusinessQuery businessQuery) {
        PageResult<BusinessVO> businessVOPaginationResult = businessService.getList(businessQuery);
        return new Result<>(businessVOPaginationResult);
    }


    @GetMapping("/admin/basic/business/info/getAll/{businessStatus}")
    @ApiOperation("后端管理:根据商家状态获取商家信息列表")
    public Result<List<BusinessVO>> listByStatus(@PathVariable("businessStatus") Integer businessStatus) {
        List<BusinessBO> list = businessService.getAll(businessStatus);
        List<BusinessVO> businessVOList = businessConverter.boListvoList(list);
        return new Result<>(businessVOList);
    }



    @PutMapping("/admin/basic/business/info/updateStatus")
    @ApiOperation("后端管理:商家账号审核/状态启用/禁用")
    public Result<Void> updateByStatus(@RequestBody BusinessParam businessParam) {
        System.out.println(businessParam);
        businessService.updateStatus(businessParam);
        return Result.success();
    }

    //    @ApiOperation("商家基本信息更新")
//    @ApiImplicitParams(
//            value = {
//                    @ApiImplicitParam(name = "businessParam", value = "BusinessParam",
//                            required = false, dataType = "BusinessParam")
//            })
//    @PutMapping("/update/{id}")
//    public Result<Void> update(@PathVariable("id") Integer id, @RequestBody @Valid BusinessParam businessParam) {
//        businessService.update(id, businessParam);
//        return Result.success();
//    }


}
